﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Devsoft.Utilities.Extentions;
using PlatForm.DataLayer;

namespace PlatForm.Controller
{
    public class OrderController
    {
        public List<Order> GetList()
        {
            return Order.Objects.ToList();
        }

        public List<Order> GetByART(string ART_No)
        {
            var ord = Order.Objects.Where(o => o.ART_No == ART_No && o.DELI_QTY > o.RECE_QTY && o.DELI_Date==DateTime.Now.Date).ToList();
            return ord;
        }

        public int Save(Order order)
        {
            var isNew = 1;
            var s = Order.Objects.FirstOrDefault(x => x.ORD_No == order.ORD_No);
            if (s != null)
            {
                Order.Objects.Delete(x => x.ORD_No == order.ORD_No);
                isNew = 0;
            }
            order.Insert(true);
            return isNew;
        }

        public void Delete(string ORD_No)
        {
            Order.Objects.Delete(x => x.ORD_No == ORD_No);
        }
    }
}
